// 1.定义router相关的逻辑
    //1.router的类型 history
    //
// 2.在vue实例中使用router
import {createRouter,createWebHistory} from "vue-router";
import Home from "../pages/Home.vue";
import About from "../pages/Detail.vue";

const routes = [
    {path:'/',name:'home',component:Home},
    {path:'/about',name:'about',component:About},
]

const router = createRouter({
    history: createWebHistory(),
    routes,
});

// 导航守卫
// 全局守卫
router.beforeEach((to, from, next) => {
    console.log("beforeEach",to,from);
    //权限控制
    if (Math.random() > 0.5) {
        next();
    }else{
        next({ name: 'home' });
    }
})



export default router;